﻿var commoncomment_itemdatabind = function(element, data, rootParent) {
    /*
    ID = comment.GUID,
    AuthorID = comment.Author,
    AuthorName = DomainUtility.GetLinkName(comment.Author, false, "fontGreen"),
    ReplyToID = comment.ExtGuid,
    ReplyToName = DomainUtility.GetLinkName(comment.ExtGuid, false, "fontGreen"),
    CreateTime = comment.CreateTime,
    Comment = comment.Detail,   
           
    <li class="single_item">
    <a class="headerlink" style="cursor: pointer">
    <img alt="" class="header" width="50px" height="50px" src="/images/user/defaulticonsmall.gif" />
    </a>
    <span class="AuthorName" html="true"></span><span class="ReplyToName" html="true">
    </span>:&nbsp
    <span class="Comment">
    </span>
    <div>
    <span class="CreateTime"></span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
    <a style="cursor: pointer" class="reply">回复</a>&nbsp&nbsp<a style="cursor: pointer" class="delete">删除</a>
    </div>
    </li>
    */
    if (data.Header && data.Header.length > 0) {
        element.find(".header").attr("src", data.Header);
    }
    element.find(".headerlink").attr("href", String.format("/space/default.aspx?userid={0}", data.AuthorID));

    var btnReply = element.find(".reply");

    btnReply.click(function() {
        var replyTo = element.find(".AuthorName").clone();
        replyTo.data("replyToID", data.AuthorID);
        var replySpan = rootParent.find(".replyName");
        replySpan.empty();
        replySpan.text(" 回复 ");
        replySpan.append(replyTo);
        var remove = $("<a style='cursor: pointer'><img alt='' src='/images/Close-1.gif'></a>");
        remove.click(function() {
            replySpan.empty();
        });
        replySpan.append($("<span>&nbsp</span>"));
        replySpan.append(remove);
        var t = replySpan.offset().top - 500;
        $(window).scrollTop(t);

    });

    var btnDelete = element.find(".delete");

    if (data.ShowDelete) {
        btnDelete.click(function() {
            if (confirm('你确认要删除吗？')) {
                $.CallSelfAjaxMethod("DeleteComment", { commentid: data.ID }, function(ret) {
                    if (ret.d != "") {
                        alert(ret.d);
                    }
                    else {
                        element.slideUp(300, function() {
                            element.remove();
                        });
                    }
                });
            }

        });
        btnDelete.show();
    }
    else {
        btnDelete.hide();
    }
};